{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "RuntimeError",
     "evalue": "imageio.ffmpeg.download() has been deprecated. Use 'pip install imageio-ffmpeg' instead.'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mRuntimeError\u001b[0m                              Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-dbadf3a8f15e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mmayavi\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmlab\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mmlab\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[1;32mimport\u001b[0m  \u001b[0mmoviepy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0meditor\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mmpy\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[0mduration\u001b[0m\u001b[1;33m=\u001b[0m \u001b[1;36m2\u001b[0m \u001b[1;31m# duration of the animation in seconds (it will loop)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\Anaconda3\\envs\\Mayavi\\lib\\site-packages\\moviepy\\editor.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     24\u001b[0m \u001b[1;31m# Checks to see if the user has set a place for their own version of ffmpeg\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     25\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetenv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'FFMPEG_BINARY'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'ffmpeg-imageio'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m'ffmpeg-imageio'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 26\u001b[1;33m     \u001b[0mimageio\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplugins\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mffmpeg\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdownload\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     27\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     28\u001b[0m \u001b[1;31m# Clips\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\Anaconda3\\envs\\Mayavi\\lib\\site-packages\\imageio\\plugins\\ffmpeg.py\u001b[0m in \u001b[0;36mdownload\u001b[1;34m(directory, force_download)\u001b[0m\n\u001b[0;32m     38\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdownload\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdirectory\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mforce_download\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m  \u001b[1;31m# pragma: no cover\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     39\u001b[0m     raise RuntimeError(\n\u001b[1;32m---> 40\u001b[1;33m         \u001b[1;34m\"imageio.ffmpeg.download() has been deprecated. \"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     41\u001b[0m         \u001b[1;34m\"Use 'pip install imageio-ffmpeg' instead.'\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     42\u001b[0m     )\n",
      "\u001b[1;31mRuntimeError\u001b[0m: imageio.ffmpeg.download() has been deprecated. Use 'pip install imageio-ffmpeg' instead.'"
     ]
    }
   ],
   "source": [
    "#Extracted from http://zulko.github.io/blog/2014/11/29/data-animations-with-python-and-moviepy/\n",
    "import numpy as np\n",
    "import mayavi.mlab as mlab\n",
    "import  moviepy.editor as mpy\n",
    "\n",
    "duration= 2 # duration of the animation in seconds (it will loop)\n",
    "\n",
    "# MAKE A FIGURE WITH MAYAVI\n",
    "\n",
    "fig_myv = mlab.figure(size=(220,220), bgcolor=(1,1,1))\n",
    "X, Y = np.linspace(-2,2,200), np.linspace(-2,2,200)\n",
    "XX, YY = np.meshgrid(X,Y)\n",
    "ZZ = lambda d: np.sinc(XX**2+YY**2)+np.sin(XX+d)\n",
    "\n",
    "# ANIMATE THE FIGURE WITH MOVIEPY, WRITE AN ANIMATED GIF\n",
    "\n",
    "def make_frame(t):\n",
    "    mlab.clf() # clear the figure (to reset the colors)\n",
    "    mlab.mesh(YY,XX,ZZ(2*np.pi*t/duration), figure=fig_myv)\n",
    "    return mlab.screenshot(antialiased=True)\n",
    "\n",
    "animation = mpy.VideoClip(make_frame, duration=duration)\n",
    "animation.write_gif(\"sinc.gif\", fps=20)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
